package com.hot100.easy;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName Demo10
 * @Description 只出现一次的数字
 * @Author zt
 * @Date 17:53 2022/6/9
 * @Version 1.0
 **/
public class Demo10 {
    public static void main(String[] args) {
        int[] nums={4,1,2,1,2};
        System.out.println(singleNumber(nums));

    }
    public static int singleNumber(int[] nums) {
        HashMap<Integer,Integer> map=new HashMap();
        for (int num : nums) {
            if(map.containsKey(num)){
                Integer integer = map.get(num);
                map.put(num,++integer);
            }else {
                map.put(num,1);
            }
        }
        Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
        for (Map.Entry<Integer, Integer> entry : entries) {
            if(entry.getValue()==1){
                return entry.getKey();
            }
        }
        return 0;
    }

}